package com.JUC.cha06.sec01;


import java.util.concurrent.TimeUnit;

class MyNumber{
    volatile int number;
    public synchronized void addPlusPlus(){
        number++;
    }
}
public class VolatileNoAtomicDemo {

    public static void main(String[] args) {

        MyNumber myNumber = new MyNumber();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    myNumber.addPlusPlus();
                }
            }).start();
        }

        // 暂停几秒钟线程
        try { TimeUnit.SECONDS.sleep(2); } catch (InterruptedException e) { e.printStackTrace(); }

        System.out.println(myNumber.number);
    }
}
